﻿<Window x:Class="Convertor.Plugin.SendEmail.SmtpClientWindows"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:Convertor.Plugin.SendEmail"
        xmlns:sm="clr-namespace:Wpf.CommonTools.SystemExtension;assembly=Wpf.CommonTools"
        xmlns:converter="clr-namespace:Wpf.CommonTools.Converter;assembly=Wpf.CommonTools"
        xmlns:helper="clr-namespace:Wpf.CommonTools.ControlHelper;assembly=Wpf.CommonTools"
        Title="Smtp Config" Width="400" Height="400"    
        KeyDown="Window_KeyDown"
        KeyUp="Window_KeyUp">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Convertor;component\Assets\Style.xaml"/>
                <ResourceDictionary Source="/Convertor;component\Assets\Lang\StringResource.en.xaml"/>
                <ResourceDictionary Source="Assets\Lang\StringResource.zh.xaml"/>
                <ResourceDictionary Source="Assets\Lang\StringResource.en.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <converter:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
            <local:TemplateViewModel x:Key="TemplateView"/>
            <local:SmtpClientTemplateConverter x:Key="SmtpClientTemplateConverter"/>
        </ResourceDictionary>
    </Window.Resources>
    <Grid DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=Config}">
        <DockPanel Margin="10" LastChildFill="True">
            <AdornerDecorator DockPanel.Dock="Top">
                <ComboBox x:Name="cbEncodings"
                          ItemsSource="{Binding Source={StaticResource TemplateView}, Path=Templates}">
                    <ComboBox.SelectedItem>
                        <MultiBinding Converter="{StaticResource SmtpClientTemplateConverter}">
                            <Binding Path="Host" />
                            <Binding Path="LoginName" />
                            <Binding Path="Port" />
                            <Binding Path="EnableSsl" />
                        </MultiBinding>
                    </ComboBox.SelectedItem>
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Path=TemplateName}"></TextBlock>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                    <sm:WatermarkService.Titlemark>
                        <TextBlock Text="{DynamicResource Plugin_SendEmail_Template}" TextAlignment="Right"/>
                    </sm:WatermarkService.Titlemark>
                </ComboBox>
            </AdornerDecorator>
            <AdornerDecorator DockPanel.Dock="Top">
                <TextBox Text="{Binding Path=Host}">
                    <sm:WatermarkService.Titlemark>
                        <TextBlock Text="{DynamicResource Plugin_SendEmail_Host}" TextAlignment="Right"></TextBlock>
                    </sm:WatermarkService.Titlemark>
                </TextBox>
            </AdornerDecorator>
            <AdornerDecorator DockPanel.Dock="Top">
                <TextBox Text="{Binding Path=Port}">
                    <sm:WatermarkService.Titlemark>
                        <TextBlock Text="{DynamicResource Plugin_SendEmail_Port}" TextAlignment="Right"></TextBlock>
                    </sm:WatermarkService.Titlemark>
                </TextBox>
            </AdornerDecorator>
            <AdornerDecorator DockPanel.Dock="Top">
                <TextBox Text="{Binding Path=Timeout}">
                    <sm:WatermarkService.Titlemark>
                        <TextBlock Text="{DynamicResource Plugin_SendEmail_TimeOut}" TextAlignment="Right"></TextBlock>
                    </sm:WatermarkService.Titlemark>
                </TextBox>
            </AdornerDecorator>
            <CheckBox DockPanel.Dock="Top"
                      x:Name="cbUseDefaultCredentials"
                          IsChecked="{Binding Path=UseDefaultCredentials}"
                          Content="{DynamicResource Plugin_SendEmail_UseDefaultCredentials}"/>

            <AdornerDecorator DockPanel.Dock="Top">
                <TextBox Text="{Binding Path=LoginName}"
                         Visibility="{Binding ElementName=cbUseDefaultCredentials, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}, ConverterParameter='0'}">
                    <sm:WatermarkService.Titlemark>
                        <TextBlock Text="{DynamicResource Plugin_SendEmail_LoginName}" TextAlignment="Right"/>
                    </sm:WatermarkService.Titlemark>
                </TextBox>
            </AdornerDecorator>
            <AdornerDecorator DockPanel.Dock="Top">
                <PasswordBox helper:PasswordBoxHelper.Attach="True" helper:PasswordBoxHelper.Password="{Binding Path=LoginPassword, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                         Visibility="{Binding ElementName=cbUseDefaultCredentials, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}, ConverterParameter='0'}">
                    <sm:WatermarkService.Titlemark>
                        <TextBlock Text="{DynamicResource Plugin_SendEmail_LoginPassword}" TextAlignment="Right"></TextBlock>
                    </sm:WatermarkService.Titlemark>
                </PasswordBox>
            </AdornerDecorator>
            <AdornerDecorator DockPanel.Dock="Top">
                <TextBox Text="{Binding Path=Reply}">
                    <sm:WatermarkService.Titlemark>
                        <TextBlock Text="{DynamicResource Plugin_SendEmail_Reply}" TextAlignment="Right"/>
                    </sm:WatermarkService.Titlemark>
                </TextBox>
            </AdornerDecorator>
            <AdornerDecorator DockPanel.Dock="Top">
                <TextBox Text="{Binding Path=DisplayName}">
                    <sm:WatermarkService.Titlemark>
                        <TextBlock Text="{DynamicResource Plugin_SendEmail_DisplayName}" TextAlignment="Right"/>
                    </sm:WatermarkService.Titlemark>
                </TextBox>
            </AdornerDecorator>

            <CheckBox DockPanel.Dock="Top"
                          IsChecked="{Binding Path=EnableSsl}"
                          Content="{DynamicResource Plugin_SendEmail_EnableSsl}"/>
            <WrapPanel HorizontalAlignment="Center" VerticalAlignment="Bottom">
                <Button Click="Button_OK_Click">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="Image/Save.png" Width="15" Margin="0,0,5,0"/>
                        <TextBlock Text="{DynamicResource OK}"/>
                    </StackPanel>
                </Button>
                <Button Content="{DynamicResource MenuCancel}" Click="Button_Cancel_Click"/>
            </WrapPanel>
        </DockPanel>
    </Grid>
</Window>
